
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>数据类型 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Landen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="字符串.html" />
    
    
    <link rel="prev" href="js简介.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../01html/html简介.html">
            
                <a href="../01html/html简介.html">
            
                    
                    HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../01html/01html.html">
            
                <a href="../01html/01html.html">
            
                    
                    a链接、图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../01html/02html.html">
            
                <a href="../01html/02html.html">
            
                    
                    列表、表格、表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../01html/h5新增.html">
            
                <a href="../01html/h5新增.html">
            
                    
                    h5新增
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../02css/css简介.html">
            
                <a href="../02css/css简介.html">
            
                    
                    CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../02css/居中、省略、清浮.html">
            
                <a href="../02css/居中、省略、清浮.html">
            
                    
                    居中、省略、清浮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../02css/浮动和定位.html">
            
                <a href="../02css/浮动和定位.html">
            
                    
                    浮动和定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../02css/变换、过渡、动画.html">
            
                <a href="../02css/变换、过渡、动画.html">
            
                    
                    变换、过渡、动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../02css/sass和rem.html">
            
                <a href="../02css/sass和rem.html">
            
                    
                    sass和rem
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../02css/flex、media、栅格化.html">
            
                <a href="../02css/flex、media、栅格化.html">
            
                    
                    flex、media、栅格化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="js简介.html">
            
                <a href="js简介.html">
            
                    
                    JavaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="回流和重绘.html">
            
                <a href="回流和重绘.html">
            
                    
                    回流和重绘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="浏览器的渲染过程.html">
            
                <a href="浏览器的渲染过程.html">
            
                    
                    浏览器的渲染过程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="十大排序算法.html">
            
                <a href="十大排序算法.html">
            
                    
                    十大排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="对象的构建.html">
            
                <a href="对象的构建.html">
            
                    
                    对象的构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="bind&call&apply.html">
            
                <a href="bind&call&apply.html">
            
                    
                    bind&call&apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="变量提升.html">
            
                <a href="变量提升.html">
            
                    
                    变量提升
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="作用域.html">
            
                <a href="作用域.html">
            
                    
                    作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="存储.html">
            
                <a href="存储.html">
            
                    
                    存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="事件.html">
            
                <a href="事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="图片预览.html">
            
                <a href="图片预览.html">
            
                    
                    图片预览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="防抖节流.html">
            
                <a href="防抖节流.html">
            
                    
                    防抖节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="同步异步.html">
            
                <a href="同步异步.html">
            
                    
                    同步异步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="babel入门.html">
            
                <a href="babel入门.html">
            
                    
                    babel入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="nvm.html">
            
                <a href="nvm.html">
            
                    
                    nvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="ES6-ES11.html">
            
                <a href="ES6-ES11.html">
            
                    
                    ES6-ES11
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >数据类型</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x6570;&#x636E;&#x7C7B;&#x578B;">&#x6570;&#x636E;&#x7C7B;&#x578B;</h2>
<p>JavaScript&#x662F;&#x4E00;&#x95E8;&#x5F31;&#x7C7B;&#x578B;&#x76F4;&#x8BD1;&#x5F0F;&#x7684;&#x811A;&#x672C;&#x8BED;&#x8A00;&#x3002;</p>
<h3 id="&#x4E00;&#x3001;&#x6709;&#x54EA;&#x4E9B;&#x6570;&#x636E;&#x7C7B;&#x578B;">&#x4E00;&#x3001;&#x6709;&#x54EA;&#x4E9B;&#x6570;&#x636E;&#x7C7B;&#x578B;</h3>
<ul>
<li>&#x7B80;&#x5355;&#x7C7B;&#x578B;(&#x503C;&#x7C7B;&#x578B;)&#xFF1A;String&#x3001;Number&#x3001;Boolean&#x3001;Null&#x3001;undefined&#x3001;Symbol</li>
<li><p>&#x590D;&#x6742;&#x7C7B;&#x578B;(&#x5F15;&#x7528;&#x7C7B;&#x578B;)&#xFF1A;Object&#x3001;Array&#x3001;Function&#x3001;Date&#x3001;Map&#x3001;Set</p>
<ul>
<li>&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;<pre><code class="lang-js"><span class="hljs-comment">// &#x57FA;&#x672C;&#x7C7B;&#x578B;</span>
<span class="hljs-keyword">var</span> a = <span class="hljs-number">5</span>;
<span class="hljs-keyword">var</span> b = a;
b = <span class="hljs-number">8</span>;
<span class="hljs-built_in">console</span>.log(a,b); <span class="hljs-comment">// 5 8</span>
<span class="hljs-comment">// &#x5F15;&#x7528;&#x7C7B;&#x578B;</span>
<span class="hljs-keyword">var</span> c = { text: <span class="hljs-string">&apos;Hello World&#xFF01;&apos;</span> };
<span class="hljs-keyword">var</span> d = c;
d.text = <span class="hljs-string">&apos;Hi!&apos;</span>;
<span class="hljs-built_in">console</span>.log(c.text, d.text); <span class="hljs-comment">// Hi! Hi!</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h3 id="&#x4E8C;&#x3001;&#x5224;&#x65AD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x65B9;&#x6CD5;">&#x4E8C;&#x3001;&#x5224;&#x65AD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x65B9;&#x6CD5;</h3>
<ol>
<li><p>typeof</p>
<pre><code class="lang-js"> <span class="hljs-keyword">typeof</span> <span class="hljs-number">123</span>; <span class="hljs-comment">// number</span>
 <span class="hljs-keyword">typeof</span> <span class="hljs-string">&apos;123&apos;</span>; <span class="hljs-comment">// string</span>
 <span class="hljs-keyword">typeof</span> <span class="hljs-literal">true</span>; <span class="hljs-comment">// boolean</span>
 <span class="hljs-keyword">typeof</span> <span class="hljs-literal">undefined</span>; <span class="hljs-comment">// undefined</span>
 <span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Symbol</span>(); <span class="hljs-comment">// symbol</span>
 <span class="hljs-keyword">typeof</span> <span class="hljs-literal">null</span>; <span class="hljs-comment">// object</span>
 <span class="hljs-keyword">typeof</span> {}; <span class="hljs-comment">// object</span>
 <span class="hljs-keyword">typeof</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{} <span class="hljs-comment">// function</span>
</code></pre>
<p>typeof&#x5728;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x4E2D;&#xFF0C;&#x9664;&#x4E86; <code>null</code> &#x90FD;&#x53EF;&#x4EE5;&#x663E;&#x793A;&#x6B63;&#x5E38;&#x7C7B;&#x578B;&#xFF0C;&#x800C;&#x5BF9;&#x4E8E;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x6765;&#x8BF4;&#xFF0C;&#x9664;&#x4E86; <code>function</code> &#x90FD;&#x4F1A;&#x663E;&#x793A;object&#x3002;</p>
</li>
<li><p>instanceof</p>
<pre><code class="lang-js"> [] <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Array</span>; <span class="hljs-comment">// true</span>
 {} <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span>; <span class="hljs-comment">// true</span>
 <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>() <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Function</span>; <span class="hljs-comment">// true</span>
 <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>() <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Date</span>; <span class="hljs-comment">// true</span>
 <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>() <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Map</span>; <span class="hljs-comment">// true</span>
 <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>() <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Set</span>; <span class="hljs-comment">// true</span>
 <span class="hljs-comment">// &#x6570;&#x7EC4;&#x8FD8;&#x53EF;&#x4EE5;&#x7528;ES6&#x65B0;&#x589E;&#x7684;Array.isArray()&#x6765;&#x5224;&#x65AD;</span>
 <span class="hljs-built_in">Array</span>.isArray([]); <span class="hljs-comment">// true</span>
 <span class="hljs-comment">// instanceof &#x8FD8;&#x53EF;&#x4EE5;&#x6D4B;&#x8BD5;&#x81EA;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;</span>
 <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>)</span>{};
 <span class="hljs-keyword">new</span> Person() <span class="hljs-keyword">instanceof</span> Person; <span class="hljs-comment">// true</span>
 <span class="hljs-keyword">new</span> Person() <span class="hljs-keyword">instanceof</span> <span class="hljs-built_in">Object</span>; <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;</p>
<blockquote>
<p>&#x6240;&#x6709;&#x7684;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x7528;instanceof&#x68C0;&#x6D4B;Object&#x90FD;&#x8FD4;&#x56DE;true&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5728;&#x539F;&#x578B;&#x94FE;&#x4E0A;&#x90FD;&#x5B58;&#x5728;Object&#x5C5E;&#x6027;&#xFF0C;&#x5373;&#x6240;&#x6709;&#x7684;&#x5F15;&#x7528;&#x7C7B;&#x578B;&#x90FD;&#x662F;Object&#x7684;&#x5B9E;&#x4F8B;&#x3002;</p>
</blockquote>
<p> &#x53E6;&#x5916;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E0D;&#x80FD;&#x7528;instanceof&#x5224;&#x65AD;</p>
</li>
<li><p>constructor</p>
<p> constructor&#x5373;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x662F;&#xFF0C;&#x53EF;&#x4EE5;&#x68C0;&#x6D4B;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x7531;&#x90A3;&#x4E2A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4EA7;&#x751F;&#x7684;&#xFF0C;&#x5B83;&#x4E5F;&#x53EF;&#x4EE5;&#x68C0;&#x6D4B;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;&#x4F46;&#x662F;&#x5982;&#x679C;&#x91CD;&#x5199;prototype&#xFF0C;constructor&#x53EF;&#x4EE5;&#x88AB;&#x6539;&#x53D8;&#x3002;</p>
<pre><code class="lang-js"> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">F</span>(<span class="hljs-params"></span>)</span>{};
 <span class="hljs-keyword">var</span> f = <span class="hljs-keyword">new</span> F();
 f.constructor === F; <span class="hljs-comment">// true</span>
 <span class="hljs-comment">// &#x91CD;&#x5199;prototype</span>
 F.prototype = { a: <span class="hljs-string">&apos;&apos;</span> };
 <span class="hljs-keyword">var</span> f1 = <span class="hljs-keyword">new</span> F();
 f1.constructor === F; <span class="hljs-comment">// false</span>
 <span class="hljs-comment">// &#x91CD;&#x5199;&#x539F;&#x578B;&#x65F6;&#x53EF;&#x4EE5;&#x7ED9;constructor&#x8D4B;&#x503C;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x4E0D;&#x4F1A;&#x88AB;&#x6539;&#x53D8;</span>
 F.prototype = {
     <span class="hljs-keyword">constructor</span>: F, 
     a: &apos;&apos;,
 };
 var f2 = new F();
 f2.<span class="hljs-keyword">constructor</span> === F; // true 
 // &#x57FA;&#x672C;&#x7C7B;&#x578B;
 var num = 1;
 num.<span class="hljs-keyword">constructor</span> === Number; // true
 &apos;1&apos;.<span class="hljs-keyword">constructor</span> === String; // true
 true.<span class="hljs-keyword">constructor</span> === Boolean; // true
 Symbol().<span class="hljs-keyword">constructor</span> === Symbol; // true
 // &#x5BF9;&#x4E8E;&#x7279;&#x6B8A;&#x7684;null&#x548C;undefined&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x5E76;&#x4E0D;&#x5141;&#x8BB8;&#x5728;&#x5916;&#x9762;&#x8BBF;&#x95EE;&#x4F7F;&#x7528;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x80FD;&#x7528;<span class="hljs-keyword">constructor</span>&#x6765;&#x5224;&#x65AD;
</code></pre>
</li>
<li><p>Object.prototype.toString.call()</p>
<p> &#x8FD9;&#x662F;&#x68C0;&#x6D4B;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x6700;&#x63A8;&#x8350;&#x6700;&#x5E38;&#x7528;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x66F4;&#x51C6;&#x786E;&#x7684;&#x5224;&#x65AD;&#x4EFB;&#x4F55;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;toString&#x662F;Object&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E0A;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x9ED8;&#x8BA4;&#x8FD4;&#x56DE;&#x5176;&#x8C03;&#x7528;&#x8005;&#x7684;&#x5177;&#x4F53;&#x7C7B;&#x578B;&#xFF0C;&#x7528;call&#x6539;&#x53D8;&#x65B9;&#x6CD5;&#x4E2D;&#x7684;this&#x5173;&#x952E;&#x5B57;&#x7684;&#x6307;&#x5411;&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65B9;&#x6CD5;&#x7684;&#x6267;&#x884C;&#x4E3B;&#x4F53;&#x6240;&#x5C5E;&#x7C7B;&#x7684;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#xFF0C;&#x8FD4;&#x56DE;&#x683C;&#x5F0F;&#x4E3A;[object String]&#x3002;</p>
<pre><code class="lang-js"> toString.call(<span class="hljs-string">&apos;&apos;</span>); <span class="hljs-comment">// [object String]</span>
 toString.call(<span class="hljs-number">1</span>); <span class="hljs-comment">// [object Number]</span>
 toString.call(<span class="hljs-literal">null</span>); <span class="hljs-comment">// [object Null]</span>
 toString.call(<span class="hljs-literal">undefined</span>); <span class="hljs-comment">// [object Undefined]</span>
 toString.call(<span class="hljs-literal">true</span>); <span class="hljs-comment">// [object Boolean]</span>
 toString.call(<span class="hljs-built_in">Symbol</span>()); <span class="hljs-comment">// [object Symbol]</span>
 toString.call({}); <span class="hljs-comment">// [object Object]</span>
 toString.call([]); <span class="hljs-comment">// [object Array]</span>
 toString.call(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>()); <span class="hljs-comment">// [object Function]</span>
 toString.call(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>()); <span class="hljs-comment">// [object Date]</span>
 toString.call(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>()); <span class="hljs-comment">// [object Map]</span>
 toString.call(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>()); <span class="hljs-comment">// [object Set]</span>
 toString.call(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>()); <span class="hljs-comment">// [object Error]</span>
</code></pre>
</li>
</ol>
<h3 id="&#x4E09;&#x3001;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x8F6C;&#x6362;">&#x4E09;&#x3001;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x8F6C;&#x6362;</h3>
<ol>
<li><p>&#x8F6C;&#x6362;&#x4E3A;&#x5E03;&#x5C14;&#x503C;</p>
<p> &#x5E03;&#x5C14;&#x8868;&#x793A;&#x4E00;&#x79CD;&#x903B;&#x8F91;&#x5B9E;&#x4F53;&#xFF0C;&#x53EF;&#x4EE5;&#x6709;&#x4E24;&#x4E2A;&#x503C;&#xFF1A; <code>true</code> &#x548C; <code>false</code> &#x3002;&#x5728;&#x6761;&#x4EF6;&#x5224;&#x65AD;&#x65F6;&#xFF0C;false&#x3001;&apos;&apos;&#x3001;null&#x3001;undefined&#x3001;NaN&#x3001;0&#x3001;-0&#x8FD9;&#x4E9B;&#x503C;&#x4E3A;false&#xFF0C;&#x5176;&#x4ED6;&#x90FD;&#x4E3A;true&#x3002;</p>
</li>
<li><p>&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;</p>
<p> X.toString()&#x3001;String()&#x3001;+&apos;&apos;</p>
<pre><code class="lang-js"> <span class="hljs-comment">// (1)&#x6570;&#x5B57;</span>
 (<span class="hljs-number">11</span>).toString(<span class="hljs-number">10</span>); <span class="hljs-comment">// &apos;11&apos; // &#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x7B26;&#x4E32;</span>
 (<span class="hljs-number">12</span>).toString(<span class="hljs-number">2</span>); <span class="hljs-comment">// &apos;1100&apos; // &#x53EF;&#x4EE5;&#x8F6C;&#x6362;&#x4E3A;&#x4E0D;&#x540C;&#x7684;&#x8FDB;&#x5236;</span>
 <span class="hljs-comment">// (2)&#x6570;&#x7EC4;</span>
 [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>].toString(); <span class="hljs-comment">// &apos;1,2&apos;</span>
 <span class="hljs-comment">// (3)&#x5BF9;&#x8C61;</span>
 ({}).toString(); <span class="hljs-comment">// &apos;[object Object]&apos;</span>
 <span class="hljs-comment">// (4)&#x5E03;&#x5C14;</span>
 <span class="hljs-literal">true</span>.toString(); <span class="hljs-comment">// &apos;true&apos;</span>
</code></pre>
</li>
<li><p>&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x5B57;</p>
<p> Number()&#x3001;parseInt()&#x3001;parseFloat()</p>
<pre><code class="lang-js"> <span class="hljs-comment">// (1)&#x5B57;&#x7B26;&#x4E32;</span>
 <span class="hljs-built_in">Number</span>(<span class="hljs-string">&apos;1&apos;</span>); <span class="hljs-comment">// 1</span>
 <span class="hljs-built_in">Number</span>(<span class="hljs-string">&apos;a&apos;</span>); <span class="hljs-comment">// NaN</span>
 <span class="hljs-comment">// (2)boolean</span>
 <span class="hljs-built_in">Number</span>(<span class="hljs-literal">true</span>); <span class="hljs-comment">// 1 // true&#x8F6C;1&#xFF0C;false&#x8F6C;0</span>
 <span class="hljs-comment">// (3)null</span>
 <span class="hljs-built_in">Number</span>(<span class="hljs-literal">null</span>); <span class="hljs-comment">// 0</span>
 <span class="hljs-comment">// (4)undefined</span>
 <span class="hljs-built_in">Number</span>(<span class="hljs-literal">undefined</span>); <span class="hljs-comment">// NaN</span>
 <span class="hljs-comment">// (5)symbol</span>
 <span class="hljs-built_in">Number</span>(<span class="hljs-built_in">Symbol</span>()) <span class="hljs-comment">// &#x62A5;&#x9519;</span>
 <span class="hljs-comment">// (6)&#x6570;&#x7EC4;</span>
 <span class="hljs-built_in">Number</span>([]); <span class="hljs-comment">// 0 // &#x7A7A;&#x6570;&#x7EC4;&#x8F6C;&#x4E3A;0</span>
 <span class="hljs-built_in">Number</span>([<span class="hljs-number">1</span>]); <span class="hljs-comment">// 1 // &#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5219;&#x5C06;&#x8FD9;&#x4E2A;&#x5143;&#x7D20;&#x8F6C;&#x4E3A;&#x6570;&#x5B57;</span>
 <span class="hljs-built_in">Number</span>([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]); <span class="hljs-comment">// NaN //&#x5B58;&#x5728;&#x591A;&#x4E2A;&#x5143;&#x7D20;&#x5219;&#x8F6C;&#x6362;&#x4E3A;NaN</span>
 <span class="hljs-comment">// (7)&#x9664;&#x4E86;&#x6570;&#x7EC4;&#x7684;&#x5F15;&#x7528;&#x7C7B;&#x578B;</span>
 <span class="hljs-built_in">Number</span>({}); <span class="hljs-comment">// NaN</span>
</code></pre>
</li>
</ol>

                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="js简介.html" class="navigation navigation-prev " aria-label="Previous page: JavaScript">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="字符串.html" class="navigation navigation-next " aria-label="Next page: 字符串">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"数据类型","level":"1.4.1","depth":2,"next":{"title":"字符串","level":"1.4.2","depth":2,"path":"md/03js/字符串.md","ref":"./md/03js/字符串.md","articles":[]},"previous":{"title":"JavaScript","level":"1.4","depth":1,"path":"md/03js/js简介.md","ref":"./md/03js/js简介.md","articles":[{"title":"数据类型","level":"1.4.1","depth":2,"path":"md/03js/数据类型.md","ref":"./md/03js/数据类型.md","articles":[]},{"title":"字符串","level":"1.4.2","depth":2,"path":"md/03js/字符串.md","ref":"./md/03js/字符串.md","articles":[]},{"title":"数组","level":"1.4.3","depth":2,"path":"md/03js/数组.md","ref":"./md/03js/数组.md","articles":[]},{"title":"回流和重绘","level":"1.4.4","depth":2,"path":"md/03js/回流和重绘.md","ref":"./md/03js/回流和重绘.md","articles":[]},{"title":"浏览器的渲染过程","level":"1.4.5","depth":2,"path":"md/03js/浏览器的渲染过程.md","ref":"./md/03js/浏览器的渲染过程.md","articles":[]},{"title":"十大排序算法","level":"1.4.6","depth":2,"path":"md/03js/十大排序算法.md","ref":"./md/03js/十大排序算法.md","articles":[]},{"title":"对象的构建","level":"1.4.7","depth":2,"path":"md/03js/对象的构建.md","ref":"./md/03js/对象的构建.md","articles":[]},{"title":"this","level":"1.4.8","depth":2,"path":"md/03js/this.md","ref":"./md/03js/this.md","articles":[]},{"title":"bind&call&apply","level":"1.4.9","depth":2,"path":"md/03js/bind&call&apply.md","ref":"./md/03js/bind&call&apply.md","articles":[]},{"title":"函数","level":"1.4.10","depth":2,"path":"md/03js/函数.md","ref":"./md/03js/函数.md","articles":[]},{"title":"变量提升","level":"1.4.11","depth":2,"path":"md/03js/变量提升.md","ref":"./md/03js/变量提升.md","articles":[]},{"title":"作用域","level":"1.4.12","depth":2,"path":"md/03js/作用域.md","ref":"./md/03js/作用域.md","articles":[]},{"title":"对象","level":"1.4.13","depth":2,"path":"md/03js/对象.md","ref":"./md/03js/对象.md","articles":[]},{"title":"存储","level":"1.4.14","depth":2,"path":"md/03js/存储.md","ref":"./md/03js/存储.md","articles":[]},{"title":"事件","level":"1.4.15","depth":2,"path":"md/03js/事件.md","ref":"./md/03js/事件.md","articles":[]},{"title":"图片预览","level":"1.4.16","depth":2,"path":"md/03js/图片预览.md","ref":"./md/03js/图片预览.md","articles":[]},{"title":"防抖节流","level":"1.4.17","depth":2,"path":"md/03js/防抖节流.md","ref":"./md/03js/防抖节流.md","articles":[]},{"title":"同步异步","level":"1.4.18","depth":2,"path":"md/03js/同步异步.md","ref":"./md/03js/同步异步.md","articles":[]},{"title":"babel入门","level":"1.4.19","depth":2,"path":"md/03js/babel入门.md","ref":"./md/03js/babel入门.md","articles":[]},{"title":"nvm","level":"1.4.20","depth":2,"path":"md/03js/nvm.md","ref":"./md/03js/nvm.md","articles":[]},{"title":"ES6","level":"1.4.21","depth":2,"path":"md/03js/ES6.md","ref":"./md/03js/ES6.md","articles":[]},{"title":"ES6-ES11","level":"1.4.22","depth":2,"path":"md/03js/ES6-ES11.md","ref":"./md/03js/ES6-ES11.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","toggle-chapters","image-captions","-anchor-navigation","-anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"image-captions":{"attributes":{"style":"left: 50%;position: relative;transform: translateX(-50%);"},"caption":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_","align":"center","variable_name":"_pictures"},"fontsettings":{"theme":"night","family":"sans","size":2},"toggle-chapters":{},"highlight":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Landen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[]},"gitbook":"3.x.x"},"file":{"path":"md/03js/数据类型.md","mtime":"2020-06-09T15:09:45.849Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T10:41:18.504Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

